home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / C++ AppleLink Messages / CPlus.Dev$ 3⁄2⁄90 / 0058-"pure base" notion-Mar90 next >
Encoding:
Text File  |  1990-03-02  |  2.2 KB  |  71 lines  |  [TEXT/GEOL]

  1. Item    5138121                         1-March-90        06:16PST
  2.  
  3. From:   NAUTIL                          France - Dev, Nautil Info Lyon,IDV
  4.  
  5. To:     CPLUS.APPLE$                    C++ Interest List--Apple Employees
  6.         CPLUS.DEV$                      C++ Interest List--Developers
  7.  
  8. Sub:    "pure base" notion
  9.  
  10. How can I define a "pure base" class wich is never directly instancied?
  11.  
  12. My code is stand-alone and must be independant of "CPlusLib.o", so I define
  13. some base classes with operators new and delete :
  14.  
  15.   class TSomeSpecialAlloc {
  16.   public:
  17.    void* operator new(size_t size) { return NewPtr(size); }
  18.    void operator delete(void* p) { DisposPtr((Ptr)p); }
  19.   };
  20.  
  21.   class TAnotherSpecialAlloc {
  22.   public:
  23.    void* operator new(size_t) { return NewPtr(size); }
  24.    void operator delete(void*) { DisposPtr((Ptr)p); }
  25.   };
  26.  
  27. Here is the "pure base" class (never directly instancied) :
  28.  
  29.   class TPureBase {
  30.   public:
  31.     TPureBase(int) {}
  32.   };
  33.  
  34. Now, I want to declare the following classes :
  35.  
  36.   class A : public TSomeSpecialAlloc, public TPureBase {
  37.   public:
  38.     A(int i) : TPureBase(i) {}
  39.   };
  40.  
  41.   class B : public TAnotherSpecialAlloc, public TPureBase {
  42.   public:
  43.     B(int i) : TPureBase(i) {}
  44.   };
  45.  
  46. The problem is that CFront (1.0B1 for MPW C++ 3.1B1) generates an allocation
  47. function for TPureBase in the A and B constructors. And this allocation
  48. involves default function in "CPlusLib.o" (arrgl!). It seems that CFront uses
  49. the following algorithm:
  50.  
  51.   1- In a constructor, generate checking for allocation.
  52.   2- In a derivated constructor, generate full constructor for the base.
  53.  
  54. I think that (at least for inline constructors!) it is not very difficult to
  55. generate correct instructions avoiding a multiple allocation checking for a
  56. multiple base classes!!! (Well, this is a poor beta version of CFront, so final
  57. release will be perfect... Isn't it?!!!).
  58.  
  59. Now, I have tried to bypass this feature declaring empty new and delete
  60. operators for class TPureBase, then declaring A and B "public TxSpecialAlloc,
  61. private TPureBase". I was thinking that, in this case, TPureBase operators was
  62. hidden for A and B. But CFront is really a facetious compiler and he said:
  63. "error: ambiguous operator ::new"! (arrgl again!).
  64.  
  65. Help !
  66. Etienne Vautherin
  67.  
  68.  
  69.  
  70.  
  71.